<template>
  <div style="font-size: 16px;font-weight: 600;"><el-radio></el-radio>新建导入任务</div>
  <div v-show="firstStep">
    <div class="main">
      <div class="main-one">
        <el-button type="primary" circle style="width:30px;height: 30px;"></el-button>
        <span>1</span>
        <p>基本信息</p>
      </div>
      <div class="hr1"></div>
      <div class="main-two">
        <el-button type="info" circle style="width:30px;height: 30px;"></el-button>
        <span>2</span>
        <p>设置对应关系</p>
      </div>
      <div class="hr2"></div>
      <div class="main-three">
        <el-button type="info" circle style="width:30px;height: 30px;"></el-button>
        <span>3</span>
        <p>完成</p>
      </div>
    </div>
    <!--第一步-->
    <el-form :model="formData1" ref="vFormRef" label-position="center" label-width="85px" :rules="rules" style="margin-top: 50px;" >
      <el-row>
        <el-col :span="16">
          <el-form-item label="批次名称"  prop="batch">
            <el-select ref="batchRef" v-model="formData1.batch" filterable allow-create placeholder="请输入"
              @change="batchChage" clearable>
              <el-option v-for="item in joinBatchList" :label="item.batch" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="所属展会"  prop="exhId">
            <el-select v-model="formData1.exhId" placeholder="请选择" clearable>
              <el-option v-for="item in exhibitionList" :label="item.exhSName" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="参会类别" prop="psjJoinType">
            <el-select v-model="formData1.psjJoinType" placeholder="请选择" clearable>
              <el-option v-for="item in psjJoinTypelist" :label="item.dictLabel" :value="item.dictValue" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="整理人">
            <el-checkbox-group v-model="formData1.collator" placeholder="请选择" clearable>
              <el-checkbox  v-for="item in exOrganizer" :key="item.userId" :label="item.userId" :value="parseInt(item.userId)">
                {{ item.remark }}
               </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="导入备注">
            <el-input v-model="formData1.remark" type="textarea" placeholder="请输入导入备注" clearable ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-upload class="upload-demo" drag :auto-upload="false" :on-change="handleFile">
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      </el-upload>
      <el-form-item style="margin-top: 50px;">
        <el-button type="primary" @click="submitForm">下一步</el-button>
        <el-button type="primary" @click="continueImport">继续导入（待处理数量{{continueNum}}条）</el-button>
      </el-form-item>
    </el-form>
  </div>
   <!--第二步-->
  <div v-show="!firstStep">
    <div class="main">
      <div class="main-one">
        <el-button type="primary" circle style="width:30px;height: 30px;"></el-button>
        <span>1</span>
        <p>基本信息</p>
      </div>
      <div class="hr1"></div>
      <div class="main-two">
        <el-button type="primary" circle style="width:30px;height: 30px;"></el-button>
        <span>2</span>
        <p>设置对应关系</p>
      </div>
      <div class="hr2"></div>
      <div class="main-three">
        <el-button type="info" circle style="width:30px;height: 30px;"></el-button>
        <span>3</span>
        <p>完成</p>
      </div>
    </div>
    <!-- <el-form :model="formData2" ref="vForm" label-position="center" style="margin-top: 50px;">
      <el-row>
        <el-col :span="12">
          <el-form-item label="请选择已有关系" >
            <el-select  ref="batchRef"  filterable allow-create  v-model="formData2.batch"  placeholder="请选择" @change="queryBatchCorrelation()" clearable>
              <el-option v-for="item in joinBatchList2" :key="item.id" :label="item.relationName" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-form-item>
          <el-button type="primary" style="margin-left: 10px;" @click="saveCorrelation">保留当前关系</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" style="margin-left: 10px;" @click="delBatchJoin">删除选中关系</el-button>
        </el-form-item>
      </el-row>
    </el-form> -->
    <el-form v-if="!firstStep" :model="formData3" ref="vForm" label-position="center" label-width="85px"
      style="margin-top: 50px;width: 1000px;">
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="姓名">
            <el-select v-model="formData3.name" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="部门">
            <el-select v-model="formData3.dept" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="英文名">
            <el-select v-model="formData3.firstEName" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="邮箱">
            <el-select v-model="formData3.email" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="公司名称">
            <el-select v-model="formData3.company" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="传真">
            <el-select v-model="formData3.fax" placeholder="请选择" @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="公司英文">
            <el-select v-model="formData3.companyEn" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="地址">
            <el-select v-model="formData3.address" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="手机一">
            <el-select v-model="formData3.mobile" placeholder="请选择" clearable>
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="英文地址">
            <el-select v-model="formData3.addressEn" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="手机二">
            <el-select v-model="formData3.mobile2" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="备注">
            <el-select v-model="formData3.remark" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="电话一">
            <el-select v-model="formData3.tel" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="数据来源">
            <el-select v-model="formData3.source" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="电话二">
            <el-select v-model="formData3.tel2" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="人员类别">
            <el-select v-model="formData3.type" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="职务">
            <el-select v-model="formData3.post" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="身份证号">
            <el-select v-model="formData3.idCard" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="行业类别">
            <el-select v-model="formData3.trade" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="微信">
            <el-select v-model="formData3.weixin" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="产品">
            <el-select v-model="formData3.productIntroduce" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="qq">
            <el-select v-model="formData3.qq" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="人员标签一">
            <el-select v-model="formData3.label" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="网址">
            <el-select v-model="formData3.website" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="7">
          <el-form-item label="人员标签二">
            <el-select v-model="formData3.label2" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7" :offset="7">
          <el-form-item label="采购意向">
            <el-select v-model="formData3.intention" placeholder="请选择" clearable @change="changeColsOptions">
              <el-option v-for="item in headerList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="parseInt(item.id)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-left: 130px;">
        <el-form-item style="margin-top: 30px;">
          <el-button type="primary" style="margin-left: 10px;" :loading="importLoadig" @click="saveImportData">开始导入</el-button>
          <!--返回-->
          <el-button type="danger" @click="firstStep = true">返回</el-button>
          <!--重置 -->
          <el-button type="primary" @click="reset()">重置</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router'
import { defineComponent, toRefs, ref, reactive, getCurrentInstance } from 'vue'
import baseService from "@/service/baseService";
import {ElMessage, ElMessageBox} from "element-plus";
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const firstStep = ref(true);
const formData1 = reactive({
  batch: '',
  exhId: '',
  exhSName: '',
  collator: [] as any,
  file: '',
  remark: '',
  psjJoinType:'',
  type:"participant_category",
  batchType: 'select',  //select选择 add新增
});
const importLoadig = ref(false);

const continueNum = ref(0);

const formData2 = reactive({
  batch: ''
});

/**
 * 此处的字段名，与java后台CrmPersonImportServiceImpl.saveBatch方法里的字段名一致，
 * 此处不能随便定义！！！
 */
let formData3 = reactive({
  id: '',
  // pjbId: '',
  name: '',
  dept: '',
  firstEName: '',
  email: '',
  company: '',
  fax: '',
  companyEn: '',
  address: '',
  mobile: '',
  addressEn: '',
  mobile2: '',
  remark: '',
  tel: '',
  source: '',
  tel2: '',
  type: '',
  post: '',
  idCard: '',
  trade: '',
  weixin: '',
  productIntroduce: '',
  qq: '',
  website: '',
  label: '',
  label2: '',
  intention:'',
}) as any;

const headerList = ref([] as any[]);
const joinBatchList = ref([] as any[]);
const joinBatchList2 = ref([] as any[]);
const exhibitionList = ref([] as any[]);
const exOrganizer = ref([] as any[]);
const psjJoinTypelist = ref([] as any[]);


const vFormRef = ref();


const rules = ref({
  batch: [{ required: true, message: t("validate.required"), trigger: "blur" }],
  exhId: [{ required: true, message: t("validate.required"), trigger: "change" }],
  psjJoinType: [{ required: true, message: t("validate.required"), trigger: "change" }],
});


const init = () => {
  queryJoinBatch();
  queryExhibition();
  getOrganizer();
  //queryJoinBatch2();
  getPsjJoinType();
  queryContinueNum();
}


const submitForm = () => {
  // 校验表单
  if (!vFormRef.value) {
    ElMessage.error('表单未初始化');
    return;
  }
  vFormRef.value.validate((valid:any) => {
    if (!valid) {
      ElMessage.error('请填写必填项');
      return false;
    }
    if (!formData1.file) {
      ElMessage.error('上传文件必填');
      return false;
    }
    const params = new FormData();
    params.append("file", formData1.file);
    params.append("batch", formData1.batch);
    params.append("exhId", formData1.exhId);
    params.append("collator", formData1.collator);
    params.append("remark", formData1.remark);
    params.append("psjJoinType", formData1.psjJoinType);
    console.log(params);
    baseService.post("/crm/crmperson/readHead", params).then((res) => {
      if (res.code === 0) {
        // 查询excel的表头
        headerList.value = res.data.headList;
        // 动态解析表头
        excelHeadRelation(res.data.relation);
        firstStep.value = false;
        // 选中的变灰色
        changeColsOptions();
        //queryBatchCorrelation();
      } else {
        ElMessage.error(res.msg);
      }
    });
    return true;
  });
};


/**
 * 保留当前关系
 */
const router = useRouter();
const saveCorrelation = () => {
  if (!formData2.batch) {
    ElMessage.warning('请选择已有关系');
    return;
  }
  baseService.post("/crm/crmbatchcorrelation/saveOrUpdate", formData3).then((res) => {
    if (res.code === 0) {
      queryJoinBatch();
      ElMessage.success('保存当前关系成功');
    } else {
      ElMessage.error(res.msg);
    }
  });
}

const saveImportData = () => {
  importLoadig.value = true;
  let hasValue = false;
  for (const key in formData3) {
    if (formData3[key] && formData3[key]!== '请选择') {
      hasValue = true;
      break;
    }
  }
  if (!hasValue) {
    ElMessage.warning('请至少选择一个下拉框的值');
    return;
  }
  const params = new FormData();
  params.append("file", formData1.file);

  // 解决后台接收为字符串的问题
  let fd1 = formData1;
  fd1.exhId = fd1.exhId + '';
  fd1.batch = fd1.batch + '';
  fd1.collator = fd1.collator + '';
  fd1.psjJoinType = fd1.psjJoinType + '';
  params.append("formData1", JSON.stringify(fd1));
  params.append("formData3", JSON.stringify(formData3));

  baseService.post("/crm/crmperson/import", params).then((res) => {
    if (res.code === 0) {
      ElMessage.success('导入完成，请到查询列表查看');
      router.push('/expocube/import-query-list');
    } else {
      ElMessage.error(res.msg);
    }
  }).finally(() => {
    importLoadig.value = false;
  });
};

/**
 * 继续执行
 */
const continueImport = () => {
  //增加确认弹窗
  ElMessageBox.confirm('是否继续导入？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    const batchId = formData1.batch + '';
    baseService.post("/crm/crmperson/continueImport", {}).then((res) => {
      if (res.code === 0) {
        ElMessage.success('导入完成，请到查询列表查看');
        router.push('/expocube/import-query-list');
      } else {
        ElMessage.error(res.msg);
      }
    });
  }).catch(() => {
    ElMessage.info('已取消');
  });

}

const excelHeadRelation = (res: any) => {
  if(res != null){
    // formData3 = res.data;
    formData3.id = res.id;
    // formData3.pjbId = res.data.pjbId;
    formData3.name = res.name
    formData3.dept = res.department
    formData3.firstEName = res.firstEName
    formData3.email = res.email
    formData3.company = res.company
    formData3.fax = res.fax
    formData3.companyEn = res.companyEn
    formData3.address = res.address
    formData3.mobile = res.mobile
    formData3.addressEn = res.addressEn
    formData3.mobile2 = res.mobile2
    formData3.remark = res.remark
    formData3.tel = res.tel
    formData3.source = res.source
    formData3.tel2 = res.tel2
    formData3.type = res.type
    formData3.post = res.position
    formData3.idCard = res.idCard
    formData3.trade = res.trade
    formData3.weixin = res.wechat
    formData3.productIntroduce = res.productIntroduce
    formData3.qq = res.qq
    formData3.website = res.website
    formData3.label = res.label
    formData3.label2 = res.label2
    formData3.intention = res.intention
  }else {
    formData3.id = '';
    // formData3.pjbId = '';
    formData3.name = '';
    formData3.dept = ''
    formData3.firstEName = '';
    formData3.email = '';
    formData3.company = '';
    formData3.fax = '';
    formData3.companyEn = '';
    formData3.address = '';
    formData3.mobile = '';
    formData3.addressEn = '';
    formData3.mobile2 = '';
    formData3.remark = '';
    formData3.tel = '';
    formData3.source = '';
    formData3.tel2 = '';
    formData3.type = '';
    formData3.post = '';
    formData3.idCard = '';
    formData3.trade = '';
    formData3.weixin = '';
    formData3.productIntroduce = '';
    formData3.qq = '';
    formData3.website = '';
    formData3.label = '';
    formData3.label2 = '';
    formData3.intention=''
  }
}

/**
 * 查询当前关系
 */
const queryBatchCorrelation = () => {
  baseService.get("/crm/crmbatchcorrelation/" + formData2.batch).then((res) => {
    if (res.code === 0) {
      if(res.data != null){
        // formData3 = res.data;
        formData3.id = res.data.id;
        // formData3.pjbId = res.data.pjbId;
        formData3.name = res.data.name
        formData3.dept = res.data.dept
        formData3.firstEName = res.data.firstEName
        formData3.email = res.data.email
        formData3.company = res.data.company
        formData3.fax = res.data.fax
        formData3.companyEn = res.data.companyEn
        formData3.address = res.data.address
        formData3.mobile = res.data.mobile
        formData3.addressEn = res.data.addressEn
        formData3.mobile2 = res.data.mobile2
        formData3.remark = res.data.remark
        formData3.tel = res.data.tel
        formData3.source = res.data.source
        formData3.tel2 = res.data.tel2
        formData3.type = res.data.type
        formData3.post = res.data.post
        formData3.idCard = res.data.idCard
        formData3.trade = res.data.trade
        formData3.weixin = res.data.weixin
        formData3.productIntroduce = res.data.productIntroduce
        formData3.qq = res.data.qq
        formData3.website = res.data.website
        formData3.label = res.data.label
        formData3.label2 = res.data.label2
      }else {
        formData3.id = '';
        // formData3.pjbId = '';
        formData3.name = '';
        formData3.dept = ''
        formData3.firstEName = '';
        formData3.email = '';
        formData3.company = '';
        formData3.fax = '';
        formData3.companyEn = '';
        formData3.address = '';
        formData3.mobile = '';
        formData3.addressEn = '';
        formData3.mobile2 = '';
        formData3.remark = '';
        formData3.tel = '';
        formData3.source = '';
        formData3.tel2 = '';
        formData3.type = '';
        formData3.post = '';
        formData3.idCard = '';
        formData3.trade = '';
        formData3.weixin = '';
        formData3.productIntroduce = '';
        formData3.qq = '';
        formData3.website = '';
        formData3.label = '';
        formData3.label2 = '';
      }

    } else {
      ElMessage.error(res.msg);
    }
  });
};



/**
 * 删除选中关系
 */
const delBatchJoin = () => {
  const objectId = {};
  const id = formData2.batch;
  // 判断batchId是否为有效的数字或字符串
  if (!isNaN(Number(id)) || typeof id === 'string') {
    baseService.delete("/crm/crmbatchcorrelation/deleteByBatchId/" + id,objectId).then((res) => {
      if (res.code === 0) {
        queryJoinBatch()
        ElMessage.success('删除选中关系成功');
      } else {
        ElMessage.error(res.msg);
      }
    });
  }
  else {
    console.log("批次不存在或batchId不是有效的数字或字符串");
  }
};

/**
 * 批次改变
 * @param val
 */
 const batchChage = (val: any) => {
  formData1.batch = val;
  //判断是选择的值，还是输入的值
  const isSelected = joinBatchList.value.some((item) => item.id === (val+''));
  formData1.batchType = isSelected ? 'select' : 'add';
  //输入的值不查后台
  if (!isSelected) {
    return;
  }
  baseService.get("/crm/crmpersonjoinbatch/" + val).then((res) => {
    if (res.code === 0) {
      formData1.exhId = res.data.exhId;
      formData1.psjJoinType = res.data.joinType ? res.data.joinType + '' : '';
      formData1.remark = res.data.remark;
      formData1.collator = res.data.collator;
      continueNum.value = res.data.continueNum;
    } else {
      ElMessage.error(res.msg);
    }
  })
};

const queryContinueNum = () => {
  baseService.get("/crm/crmpersonjoinbatch/queryContinueNum").then((res) => {
    if (res.code === 0) {
      continueNum.value = res.data.continueNum;
    } else {
      ElMessage.error(res.msg);
    }
  })
}

/**
 * 上传文件
 * @param file
 */
const handleFile = (file: any) => {
  formData1.file = file.raw
}


/**
 * 批次列表
 */
const queryJoinBatch = () => {
  baseService.post("/crm/crmpersonjoinbatch/list").then((res) => {
    if (res.code === 0) {
      joinBatchList.value = res.data;
    } else {
      ElMessage.error(res.msg);
    }
    return joinBatchList.value.sort((a, b) => {
      if (a.template < b.template) return 1;
      if (a.template > b.template) return -1;
      return 0;
    });
  });
}


/**
 * 所属关系
 */
const queryJoinBatch2 = () => {
  baseService.get("/crm/crmbatchcorrelation/getList").then((res) => {
    if (res.code === 0) {
      joinBatchList2.value = res.data;
    } else {
      ElMessage.error(res.msg);
    }
    return joinBatchList.value.sort((a, b) => {
      if (a.template < b.template) return 1;
      if (a.template > b.template) return -1;
      return 0;
    });
  });
}

/**
 * 展会列表
 */
const queryExhibition = () => {
  baseService.post("/crm/crmexhibition/list", {}).then((res) => {
    if (res.code === 0) {
      exhibitionList.value = res.data;
    } else {
      ElMessage.error(res.msg);
    }
  })
}

/**
 * 整理人
 */
const getOrganizer = () => {
  return baseService.post("/sys/user/usersByType", {type: 7}).then((res) => {
    if (res.code !== 0) {
      return ElMessage.error(res.msg);
    }
    exOrganizer.value = res.data;
  });
};

/**
 * 参会类别
 */
 const getPsjJoinType = () => {
  return baseService.get("/sys/dict/data/listByType",{type:formData1.type}).then((res) => {
    if (res.code !== 0) {
      return ElMessage.error(res.msg);
    }
    psjJoinTypelist.value = res.data;
  });
};




/**
 * 重置表单
 */
 const reset = () => {
  // 遍历 formData3 的所有属性，将其设置为空字符串或默认值
  for (const key in formData3) {
    if (Object.hasOwnProperty.call(formData3, key)) {
      formData3[key] = '';
    }
  }
};

/**
 * 下拉框中已经被选择的移除掉
 * @param options
 * @param value
 */
const changeColsOptions = () => {
  for(let j = 0; j < headerList.value.length; j++) {
    headerList.value[j].disabled = false;
  }

  for (let key in formData3) {
    for(let j = 0; j < headerList.value.length; j++) {
      if (formData3.hasOwnProperty(key)) {
        if (headerList.value[j].id === formData3[key]) {
          headerList.value[j].disabled = true;
        }
      }
    }
  }
}



init();

</script>

<style lang="scss" scoped>
.message {
  font-size: 14px;
  font-weight: 600
}

.el-input {
  width: 300px;
}

.el-select {
  width: 300px;
}

.full-width-input {
  width: 300px;
}

.main {
  display: flex;
  margin: 0 auto;
  width: 700px;
}

main .main-one,
.main-two,
.main-three {
  width: 200px;
  height: 50px;
  text-align: center;
}

.main-one span {
  display: block;
  width: 50px;
  font-size: 18px;
  line-height: 30px;
  margin: 0 auto;
  color: #fff;
  margin-top: -28px;
}

.main-two span {
  display: block;
  width: 50px;
  line-height: 30px;
  margin: 0 auto;
  color: #fff;
  margin-top: -28px;
  font-size: 18px;
}

.main-three span {
  display: block;
  width: 50px;
  line-height: 30px;
  margin: 0 auto;
  color: #fff;
  margin-top: -28px;
  font-size: 18px;
}

.hr1,
.hr2 {
  width: 500px;
  height: 16px;
  border-bottom: 2px solid #898888;
}

p {
  margin-left: 6px;
}

.el-form {
  width: 630px;
  margin: 30px auto;
}

::v-deep .el-icon-upload {
  width: 50px;
  height: 50px;
}

.el-col-offset-7 {
  margin-left: 14%;
}
::v-deep .el-textarea__inner {
  height: 100px;
}
</style>
